<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<!-- 基本样式 -->
<link href="/hmp/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="/hmp/css/style.css?v=4.1.0" rel="stylesheet">
<link href="/hmp/layui/layui/css/layui.css" rel="stylesheet">

</head>

<body class="gray-bg">
	<div class="wrapper wrapper-content">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm">
							<input id="parentId" name="parentId" type="hidden"
								value="${parentId}">
							<div class="form-group">
								<label class="col-sm-3 control-label">上级菜单：</label>
								<div class="col-sm-8">
									<input id="" name="" class="form-control" type="text"
										value="${pName}" readonly>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">菜单类型：</label>
								<div class="col-sm-8">
								
									<label class="radio-inline"> 
										<input type="radio"
										name="leaf" value="1"  /> 目录
									</label> 
									<#if parentId!=1>
									<label class="radio-inline"> <input type="radio"
										name="leaf" value="0" /> 菜单
									</label> 
									<label class="radio-inline"> <input type="radio"
										name="leaf" value="2" /> 按钮
									</label>
									</#if>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">菜单名称：</label>
								<div class="col-sm-8">
									<input id="name" name="name" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">链接地址：</label>
								<div class="col-sm-8">
									<input id="url" name="url" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">权限标识：</label>
								<div class="col-sm-8">
									<input id="perms" name="perms" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">排序号：</label>
								<div class="col-sm-8">
									<input id="sort" name="sort" class="form-control"
										type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">图标：</label>
								<div class="col-sm-6">
									<input id="icon" name="icon" class="form-control" type="text"
										placeholder="例如：fa fa-circle-o">
								</div>
								<input id="ico-btn" class="btn btn-warning" type="button"
									value="选择图标">
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button class="layui-btn" lay-submit lay-filter="menu-form">立即提交</button>
								</div>
							</div>
						</form>

					</div>
				</div>
			</div>
		</div>
	</div>
</body>

<script src="/hmp/js/jquery.min.js"></script>
<script src="/hmp/js/bootstrap.min.js"></script>
<script src="/hmp/layui/layui/layui.js"></script>
<!-- jQuery Validation plugin javascript-->
<script src="/hmp/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/hmp/js/plugins/validate/messages_zh.min.js"></script>

<script type="text/javascript">
$(function(){
	
	     var pid=$("#parentId").val();
	     if(pid==1)
	     {
	    	 //0  代表是索引 
	    	 $("[name='leaf']:eq(0)").attr("checked","checked");
	     }
		 
	
	 validateRule();
	//全局layui 定义  
	layui.use('layer', function() {
		var layer = layui.layer;
		//打开图标列表
	    $("#ico-btn").click(function(){
	        layer.open({
	            type: 2,
				title:'图标列表',
	            content: '/FontIcoList.html',   //一直是放在public下面 直接 访问到了 
	            area: ['480px', '90%'],
	            success: function(layero, index){
	                //var body = layer.getChildFrame('.ico-list', index);
	                //console.log(layero, index);
	            }
	        });
	    });
	}); 
	
	
});

$.validator.setDefaults({
	//表单提交
	submitHandler : function() {
		submit01();
	}
});

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			},
			leaf : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入菜单名"
			},
			leaf : {
				required : icon + "请选择菜单类型"
			}
		}
	})
}


function submit01() {
	$.ajax({
		cache : true,////cache的作用就是第一次请求完毕之后，如果再次去请求，可以直接从缓存里面读取而不是再到服务器端读取。
		type : "POST",
		url : "/menu/save",
		data : $('#signupForm').serialize(), //a=1&b=2&c=3&d=4&e=5   序列化
		async : false,//true，即为异步方式  不会等待ajax请求返回的结果，会直接执行ajax后面的语句
		//false  ajax请求为同步请求，在没有返回值之前， 后面代码不会执行的。
		error : function(request) {
			parent.laryer.alert("网络错误!");
		},
		success : function(data) {
			if (data.code ==200) {
				parent.layer.msg(data.msg);
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				layer.alert(data.msg)
			}
		}
	});
}


</script>

</html>
